package com.gwq.computed;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.gwq.utils.DateUtils;
import com.gwq.utils.StringUtils;

import java.io.*;
import java.util.Date;

public class ExerciseSheet2 {

    private static final short COLUMN_NUMBER=5;


    //打印
    private void formattedDisplay(Exercise2 exercise2,int columns){
        int i=0;
        while (exercise2.hasNext()){
            if(i++ % columns==0){
                System.out.println();
            }
            System.out.print(exercise2.next().asString()+"\t\t");
        }
    }


    public void formattedDisplay(Exercise2 exercise2){
        formattedDisplay(exercise2,COLUMN_NUMBER);
    }

    private static void print(String str){
        System.out.println(str);
    }

    public static void main(String[] args) throws IOException {

        ExerciseSheet2 sheet2 = new ExerciseSheet2();
        Exercise2 exercise2 = new Exercise2();
        exercise2.generateAdditionExercise(50);
//        exercise2.GenerateSubstractExercise(50);
        System.out.println("---- generate and display add exercises ----");
//        sheet2.formattedDisplay(exercise2,5);


        File file = new File(DateUtils.getYyyyMMddHHmmss()+".txt");
        if (file.exists()) {
            System.out.println("文件存在");
        } else {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("文件创建成功");
        }
        //将list写入文件
        Writer out = new FileWriter(file);
        BufferedWriter bw= new BufferedWriter(out);


        int i=0;
        bw.write("\t\t\t---  请完成以下算式   ---");
        while (exercise2.hasNext()){
            if(i++ % 5==0){
                bw.newLine();
            }
            bw.write(exercise2.next().asString()+"\t;"+"\t\t");
        }

        bw.newLine();
        bw.flush();
        bw.close();

    }
}
